package com.xquant.trade.risk.entity;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class CombinedMonitor {

    private String uuICode;
    private String uuAType;
    private String uuMType;
    private String uuIName;
    private double priceOffset;
    private double volOffset;
    private String groupInfo;
    private String sceneID;
    private double spotPriceInc;
    private double volSurfaceInc;
    private double calcPrice;
    private String groupId;
    private String groupName;
    private String tradeStatus;
    private String productType;

    private double yield; // ADD,UPDATE,DELETE
    private double realizedYield;
    private double premium;
    private double exerciseAmount;

    private String uICode;
    private String uAType;
    private String uMType;
    private String uIName;
    private double uPrice;
    private String instrument;
    private String exerciseType;
    private String eventStatus;
    private String eventExercise;

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getuICode() {
        return uICode;
    }

    public void setuICode(String uICode) {
        this.uICode = uICode;
    }

    public String getuAType() {
        return uAType;
    }

    public void setuAType(String uAType) {
        this.uAType = uAType;
    }

    public String getuMType() {
        return uMType;
    }

    public void setuMType(String uMType) {
        this.uMType = uMType;
    }

    public String getuIName() {
        return uIName;
    }

    public void setuIName(String uIName) {
        this.uIName = uIName;
    }

    public double getuPrice() {
        return uPrice;
    }

    public void setuPrice(double uPrice) {
        this.uPrice = uPrice;
    }

    public String getEventExercise() {
        return eventExercise;
    }

    public void setEventExercise(String eventExercise) {
        this.eventExercise = eventExercise;
    }

    public String getInstrument() {
        return instrument;
    }

    public void setInstrument(String instrument) {
        this.instrument = instrument;
    }

    public String getEventStatus() {
        return eventStatus;
    }

    public void setEventStatus(String eventStatus) {
        this.eventStatus = eventStatus;
    }

    public double getYield() {
        return yield;
    }

    public void setYield(double yield) {
        this.yield = yield;
    }

    public double getRealizedYield() {
        return realizedYield;
    }

    public void setRealizedYield(double realizedYield) {
        this.realizedYield = realizedYield;
    }

    public String getExerciseType() {
        return exerciseType;
    }

    public void setExerciseType(String exerciseType) {
        this.exerciseType = exerciseType;
    }

    public double getPremium() {
        return premium;
    }

    public void setPremium(double premium) {
        this.premium = premium;
    }

    public double getExerciseAmount() {
        return exerciseAmount;
    }

    public void setExerciseAmount(double exerciseAmount) {
        this.exerciseAmount = exerciseAmount;
    }

    public String getTradeStatus() {
        return tradeStatus;
    }

    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    private List<CombinedMonitorDetail> details = new ArrayList<>();

    public String getUuICode() {
        return uuICode;
    }

    public void setUuICode(String uuICode) {
        this.uuICode = uuICode;
    }

    public String getUuAType() {
        return uuAType;
    }

    public void setUuAType(String uuAType) {
        this.uuAType = uuAType;
    }

    public String getUuMType() {
        return uuMType;
    }

    public void setUuMType(String uuMType) {
        this.uuMType = uuMType;
    }

    public String getUuIName() {
        return uuIName;
    }

    public void setUuIName(String uuIName) {
        this.uuIName = uuIName;
    }

    public double getPriceOffset() {
        return priceOffset;
    }

    public void setPriceOffset(double priceOffset) {
        this.priceOffset = priceOffset;
    }

    public double getVolOffset() {
        return volOffset;
    }

    public void setVolOffset(double volOffset) {
        this.volOffset = volOffset;
    }

    public double getNpv() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getNpv(),2)).sum();
    }

    public double getPlFloat() {
        return details.stream().mapToDouble(CombinedMonitorDetail::getPlFloat).sum();
    }

    public double getDelta() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getDelta(),2)).sum();
    }

    public double getCashDelta() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getCashDelta(),2)).sum();
    }

    public double getGamma() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getGamma(),2)).sum();
    }

    public double getCashGamma() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getCashGamma(),2)).sum();
    }

    public double getVega() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getVega(),2)).sum();
    }

    public double getRho() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getRho(),2)).sum();
    }

    public double getTheta() {
        return details.stream().mapToDouble(detail -> formatNumber(detail.getTheta(),2)).sum();
    }

    public List<CombinedMonitorDetail> getDetails() {
        return details;
    }

    public void setDetails(List<CombinedMonitorDetail> details) {
        this.details = details;
    }

    public double getSpotPriceInc() {
        return spotPriceInc;
    }

    public void setSpotPriceInc(double spotPriceInc) {
        this.spotPriceInc = spotPriceInc;
    }

    public double getVolSurfaceInc() {
        return volSurfaceInc;
    }

    public void setVolSurfaceInc(double volSurfaceInc) {
        this.volSurfaceInc = volSurfaceInc;
    }

    public String getGroupInfo() {
        return groupInfo;
    }

    public void setGroupInfo(String groupInfo) {
        this.groupInfo = groupInfo;
    }

    public String getSceneID() {
        return sceneID;
    }

    public void setSceneID(String sceneID) {
        this.sceneID = sceneID;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public double getCalcPrice() {
        return calcPrice;
    }

    public void setCalcPrice(double calcPrice) {
        this.calcPrice = calcPrice;
    }

    private Double formatNumber(Double val,int scale){
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        val = Double.valueOf(decimalFormat.format(val));
        return val;
    }
}
